<?php

namespace App\Console\Commands\Redis;

use Illuminate\Console\Command;
use Illuminate\Redis\Connectors\PhpRedisConnector;
use Illuminate\Redis\Connectors\PredisConnector;

class DemoCommand extends Command
{
    protected $signature = 'redis:demo';

    protected $description = 'Command description';

    public function handle()
    {
        $config = config('database.redis.default');
        $options = config('database.redis.options');

        $redis = $this->createPhpRedis($config, $options);
        $redis->sAddArray('phpredis', ['a','b']);
        $this->info('phpredis run');

        $redis = $this->createPredis($config, $options);
        $redis->sAdd('predis', ['a','b']);
        $this->info('predis run');
    }

    private function createPhpRedis($config, $options)
    {
        $connector = new PhpRedisConnector();
        return $connector->connect($config, $options);
    }

    private function createPredis($config, $options)
    {
        $connector = new PredisConnector();
        return $connector->connect($config, $options);
    }
}
